package com.weilele.leisure.time

import com.weilele.base.library.BaseBindingActivity
import com.weilele.base.library.SwitchView
import com.weilele.leisure.time.databinding.ActivityMainBinding
import com.weilele.leisure.time.leancloud.AVOSDb
import com.weilele.leisure.time.leancloud.AppUpdateDialog
import com.weilele.leisure.time.ui.fragment.HomeFragment
import com.weilele.leisure.time.ui.module.main.HomePagerFragment
import com.weilele.leisure.time.ui.module.video_cache.VideoCacheFragment
import com.weilele.mvvm.base.livedata.LiveDataWrap
import com.weilele.mvvm.view.SimpleSwitchView

class MainActivity : BaseBindingActivity<ActivityMainBinding>() {

    override fun initData() {
        super.initData()
        checkUpdate()
        ShortcutActivity.initShortcut()
    }


    override fun isNeedSwitchView(): Boolean {
        return true
    }

    override fun onBackPressed() {
//        super.onBackPressed()
    }

    //检查版本更新
    private fun checkUpdate() {
        showLoadingView(SwitchView.LoadingBean(getString(R.string.check_update)))
        AVOSDb.getAppUpdateInfo {
            if (it == null) {
                toNextPage()
            } else {
                if (!AppUpdateDialog.show(this, it)) {
                    toNextPage()
                }
            }
        }
    }

    private fun toNextPage() {
        //HomeFragment.open(this)
        HomePagerFragment.open(this)
        finishAfterTransition()
    }
}